﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using MINERP.MODEL.PrintManage;
using MINERP.BLL.PrintManage;
using MINERP.DAL;
namespace MINERP.PrintManage
{
    public partial class FrmCalibration : Form
    {
        private PaperInfoBLL bll = new PaperInfoBLL();
        private PaperInfo paperInfo = null;
        private int paperId;

        public FrmCalibration()
        {
            InitializeComponent();
        }

        public FrmCalibration(int paperId)
        {
            this.paperId = paperId;
            InitializeComponent();
        }
        private void FrmCalibration_Load(object sender, EventArgs e)
        {
            paperInfo = bll.GetPaperInfoObj(paperId);
            LinkGridview();
            ShowOldData();
        }

        private void LinkGridview()
        {
            gridControlRecord.DataSource = bll.GetRecords(paperId);
        }

        private void ShowOldData()
        {
            txtPaperId.Text = paperId.ToString();
            txtPaperLength.Text = paperInfo.Length.ToString();
            txtPaperEnd.Text = paperInfo.EndPaperLength.ToString();
        }

        private void btnRePrint_Click(object sender, EventArgs e)
        {

        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if(DataCheck())
            {
                double paperLength =Convert.ToDouble(txtPaperLength.Text);
                double paperEndLength =Convert.ToDouble(txtPaperEnd.Text);
                bll.CalibrationPaper(paperId, paperLength, paperEndLength);
                MessageBox.Show("更新成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private bool DataCheck()
        {

            if (string.IsNullOrEmpty(txtPaperEnd.Text))
            {
                txtPaperEnd.Focus();
                MessageBox.Show("请输入纸尾长度","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                return false;
            }
            if (string.IsNullOrEmpty(txtPaperLength.Text))
            {
                txtPaperLength.Focus();
                MessageBox.Show("请输入纸长度", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            return true;
        }


    }
}
